﻿<?php 
class admin
{
function title()
{
	return 'Administracja';
}

function indexAction()
{
	global $debuge_mode, $cmd, $id, $error;
	if($_SESSION['admin'] == 0)
	{
		if($cmd == '')
			$this->login_form();

		if($cmd == 'login')
			$this->login_check();
	}
	else
	{
		$this->adminmenu();
		$this->linklist();
#=====================================================#
	if($cmd == 'galerytable')
		$this->galerytable();
	if($cmd == 'galeryedit')
		$this->galeryedit($id);
	elseif($cmd == 'galerysave')
		$this->galerysave();
	elseif($cmd == 'galerydel')
		$this->galerydel();
	elseif($cmd == 'galeryactive')
		$this->galeryactive();
	elseif($cmd == 'galeryadd')
		$this->galeryadd();
	elseif($cmd == 'photoadd')
		$this->photoadd();
	elseif($cmd == 'creategalery')
		$this->creategalery();
#=====================================================#
	if($cmd == 'newstable')
		$this->newstable();
	if($cmd == 'newsedit')
		$this->newsedit($id);
	elseif($cmd == 'newssave')
		$this->newsSave();
	elseif($cmd == 'newspublic')
		$this->newsPublic();
	elseif($cmd == 'newsdel')
		$this->newsDel();
	elseif($cmd == 'newsadd')
		$this->newsAdd();
#=====================================================#
	elseif($cmd == 'articletable')
		$this->articletable();
	elseif($cmd == 'articleadd')
		$this->articleAdd();
	elseif($cmd == 'articleedit')
		$this->articleEdit($id);
	elseif($cmd == 'articlesave')
		$this->articleSave();
	elseif($cmd == 'articledel')
		$this->articledel();
#=====================================================#
	elseif($cmd == 'projecttable')
		$this->projecttable();
	elseif($cmd == 'projectadd')
		$this->projectadd();
	elseif($cmd == 'projectedit')
		$this->projectedit($id);
	elseif($cmd == 'projectsave')
		$this->projectsave();
	elseif($cmd == 'projectdel')
		$this->projectdel();
	elseif($cmd == 'projectpublic')
		$this->projectpublic();
#=====================================================#
	elseif($cmd == 'uploadstable')
		$this->uploadstable();
	elseif($cmd == 'upload')
		$this->upload();
	elseif($cmd == 'uploaded')
		$this->uploaded();
	elseif($cmd == 'filedel')
		$this->filedel();
	}
}

function adminmenu()
{
	echo '<table border=0 width=560px  align=center cellspacing="5" cellpadding="5">
<tr>
<td align=center><a href="index.php?module=admin&cmd=newstable"><img src="images/news.png" border=0><br>Aktualności</a></td>
<td align=center><a href="index.php?module=admin&cmd=articleedit&id=1"><img src="images/news.png" border=0><br>Strona główna</td>
<td align=center><a href="index.php?module=admin&cmd=articleedit&id=2"><img src="images/artykuly.png" border=0><br>O nas</td>
<td align=center><a href="index.php?module=admin&cmd=articleedit&id=5"><img src="images/artykuly.png" border=0><br>Władza i członkowie</td>
<td align=center><a href="index.php?module=admin&cmd=articleedit&id=6"><img src="images/artykuly.png" border=0><br>Statut</td></tr>
<tr>
<td align=center><a href="index.php?module=admin&cmd=articleedit&id=8"><img src="images/artykuly.png" border=0><br>Piszą o nas<br></a></td>
<td align=center><a href="index.php?module=admin&cmd=projecttable"><img src="images/artykuly.png" border=0><br>Zarządzanie<br>Projektami</a></td>
<td align=center><a href="index.php?module=admin&cmd=galerytable"><img src="images/galeria.png" border=0><br>Zarządzanie<br>Galeriami</a></td>
<td align=center><a href="index.php?module=admin&cmd=uploadstable"><img src="images/upload.png" border=0><br>Zarządzanie<br>plikami</a></td>
<td align=center><a href="index.php?module=admin&cmd=articletable"><img src="images/artykuly.png" border=0><br>Zarządzanie<br>artykułami</a></td></tr>
<tr>
<td colspan=5 align=center><a href="index.php?module=admin&cmd=logout"><img src="images/wyloguj.png" border=0><br>Wyloguj</a></td>
</tr>
</table><hr>';
}

function filedel()
{
	global $path;
	if(unlink($path))
	{
		echo '<b>Plik '.$path.' został usunięty</b><hr>';
		$this->uploadstable();
	}
	else
		echo 'wystąpił błąd podczas usuwania pliku: '.$path;
}

function uploadstable()
{
	$delimiter = "\n";
	$directory = 'upload';
	$this->upload();
	echo '<hr>';
	if (is_dir($directory)) 
	{
		$path = $directory.'/*.*';
		foreach (glob($path) as $file)
			echo '<a href="'.$file.'">'.utf8_encode($file).'</a> <a href="index.php?module=admin&cmd=filedel&path='.$file.'">[usuń]</a><hr>';
	}
}

function articletable()
{
	echo '<b><a href=index.php?module=admin&cmd=articleadd>Dodaj nowy artykuł (podstrone)</a></b><br><hr>';
	global $error, $database;
	$database->query("SELECT * FROM artykuly;");
	$result = $database->result;
	while($r=mysql_fetch_array($result))
	{
		echo '<b>'.stripslashes($r["tytul"]).'</b> ';
		if($_SESSION['admin'] != NULL)
		{
			echo '<a href=index.php?module=admin&cmd=articleedit&id='.$r['ID'].'>[Edycja] </a>| ';
			if ($r['active']!=1)
				echo '<a href=index.php?module=admin&cmd=articlepublic&id='.$r['ID'].'>[Opublikuj]</a> | ';
			echo '<a href=index.php?module=admin&cmd=articledel&id='.$r['ID'].'>[Usuń]</a>';
		}
		echo '<hr>';
	}
}

function newstable()
{
	global $database;
	echo '<b><a href=index.php?module=admin&cmd=newsadd>Dodaj nowy news</a></b><br><hr>';
	$database->query("SELECT * FROM news ORDER BY ID DESC");
	while($r=mysql_fetch_array($database->result))
	{
		echo '<b>'.stripslashes($r["nazwa"]).'</b> ';
		echo '<a href=index.php?module=admin&cmd=newsedit&id='.$r['ID'].'>[Edycja] </a>| ';
		if ($r['active']!=1)
			echo '<a href=index.php?module=admin&cmd=newspublic&id='.$r['ID'].'>[Opublikuj]</a> | ';
		echo '<a href=index.php?module=admin&cmd=newsdel&id='.$r['ID'].'>[Usuń]</a>';
		
		echo '<hr>';
	}
}

function galerytable()
{
	global $database;
	echo '<b><a href=index.php?module=admin&cmd=galeryadd>Dodaj nową galerię</a></b><br><hr>';
	$database->query("SELECT * FROM galerie ORDER BY nazwa");
	while($r=mysql_fetch_array($database->result))
	{
		echo '<b><a style="cursor: pointer; cursor: hand;" onclick="getData(\'ajax.php?module=galery&id='.$r['ID'].'\', \'div1\')">'.stripslashes($r["nazwa"]).'</a></b>';
		if($_SESSION['admin'] != NULL)
		{
			echo ' <a href=index.php?module=admin&cmd=galeryedit&id='.$r['ID'].'>[Edycja] </a> | ';
			if ($r['active']!=1)
				echo '<a href=index.php?module=admin&cmd=galeryactive&id='.$r['ID'].'>[Opublikuj] </a> | ';

			echo '<a href=index.php?module=admin&cmd=galerydel&id='.$r['ID'].'>[Usuń] </a>';
		}
		echo '<br><hr><br>'; 
	}
}

function login_form()
{
	echo '<center><form action = index.php?module=admin&cmd=login method=post>
		<table border=0>
		<tr>
			<td>login: </td><td><input type=text size=15 name=nick></td>
		</tr>
		<tr>
			<td>pass: </td><td><input type=password name=pass size=15></td>
		</tr>
		<tr>
			<td colspan=2 align=center><input type=submit value="Zaloguj"></td>
		</tr>
		</table>
		</form></center>
	';
}

function login_check()
{
	global $debuge_mode, $nick, $pass;
	if($nick == 'admin' && $pass == 'bociany')
	{
		$_SESSION['admin'] = 1;
		echo '<center><img src="images/ok.png"> Zostałeś poprawnie zalogowany</center>';
		$this->linklist();
		$this->adminmenu();
	}
	else
	{
		echo '<img src="images/no.png"> wpisales niepoprawne haslo i login';
	}
}

function linklist()
{
	global $database;
	$output = '';
	$delimiter = "\n";
	$output .= 'var tinyMCELinkList = new Array(';
	$database->query("SELECT * FROM artykuly");
	while($r=@mysql_fetch_array($database->result))
	{
		$link = 'index.php?module=article&id='.$r['ID'];
		$output .= $delimiter. '["[A] '.stripslashes($r["tytul"]). '", "'.$link. '"],';
	}
	$database->query("SELECT * FROM galerie");
	while($r=@mysql_fetch_array($database->result))
	{
		$link = 'index.php?module=galery&id='.$r['ID'];
		$output .= $delimiter. '["[G] '.stripslashes($r["nazwa"]). '", "'.$link. '"],';
	}
	$directory = 'upload';
	if (is_dir($directory)) 
	{
		$path = $directory.'/*.*';
		foreach (glob($path) as $file)
			$output .= $delimiter. '["[F] '. utf8_encode($file). '", "'. utf8_encode("$file"). '"],';
		$output = substr($output, 0, -1);
		$output .= $delimiter;
	}
	$output .= ');';
	$fp = fopen ("js/lists/links.js", "w");
	fwrite($fp, $output);
}

function logout()
{

	$_SESSION['admin'] = 0;
	echo 'zostales poprawnie wylogowany';
}

function newsEdit($id)
{
	$this->photoRefresh('upload', 1);
	global $debuge_mode, $id, $error,$database;
	$database->query("SELECT * FROM news WHERE ID=$id");
	if($r=@mysql_fetch_array($database->result))
		echo '<form action = index.php?module=admin&cmd=newssave method=post>
<table border=0>
<tr><td><input type=text name=nazwa style="width: 490px;" value="'.stripslashes($r["nazwa"]).'"> numer: '.$r['ID'].'</td></tr>
<tr><td><textarea  id="elm2" name="tekst" rows="15" cols="80" style="width: 80%">'.stripslashes($r["short"]).'</textarea></td></tr>
<tr><td><input type=submit value="Zapisz"></td></tr><input type=hidden name=id value='.$id.'></table></form>';
	else
		echo $error[7];
}

function newsSave()
{
	global $debuge_mode, $id, $tekst, $nazwa, $error, $database;
	$database->query("UPDATE news SET short='".addslashes($tekst)."', nazwa='".addslashes($nazwa)."' WHERE ID=$id");
	$this->newstable();
}


function newsPublic()
{
	global $debuge_mode, $id, $tekst, $nazwa, $error, $database;
	$database->query("UPDATE news SET active=1 WHERE ID=$id");
	echo '<b>News zostal opublikowany</b><hr>';
	$this->newstable();
}

function newsAdd()
{
	global $debuge_mode, $id, $error, $database;
	$admin = $_SESSION['id'];
	$database->query("INSERT INTO news VALUE(null, now(), 'wpisz nazwe newsa', 'wpisz tresc', 0)");
	$id = mysql_insert_id();
	$this->newsEdit($id);
}

function newsDel()
{
	global $debuge_mode, $id, $error;
	$query="DELETE FROM news Where id=$id";
	if(@mysql_query($query))
	{
		echo '<b>News został usunięty</b><hr>';
		$this->newstable();
	}
	else
		echo $error[7];
}
function articledel()
{
	global $debuge_mode, $id, $error;
	$query="DELETE FROM artykuly Where id=$id";
	if(@mysql_query($query))
	{
		echo '<b>Artykuł został usunięty</b><hr>';
		$this->articletable();
	}
	else
		echo $error[7];
}
function articleAdd()
{
	global $debuge_mode, $id, $error;
	$admin = $_SESSION['id'];
	$query="INSERT INTO artykuly VALUE(null, 'wpisz nazwe', 'wpisz zawartosc')";
	if(@mysql_query($query))
	{
		$id = mysql_insert_id();
		$this->articleEdit($id);
	}
	else
		echo $error[7];
}

function articleEdit($id)
{
	$this->photoRefresh('upload', 1);
	global $debuge_mode, $error;
	$query="SELECT * FROM artykuly WHERE ID=$id";
	$result=mysql_query($query);
	if($r=@mysql_fetch_array($result))
		echo '<form action = index.php?module=admin&cmd=articlesave method=post>
<table border=0>
<tr><td><input type=text name=nazwa style="width: 490px;" value="'.stripslashes($r["tytul"]).'"> numer: '.$r['ID'].'</td></tr>
<tr><td><textarea id="elm2" name="tekst" style="width: 555px; height: 600px" cols="80" style="width: 80%">'.stripslashes($r["tresc"]).'</textarea></td></tr>
<input type=hidden name=id value='.$id.'>
</table></form>';
	else
		echo $error[7];
}

function articleSave()
{
	global $debuge_mode, $id, $tekst, $nazwa, $error;
	$query="UPDATE artykuly SET tresc='".addslashes($tekst)."', tytul='".addslashes($nazwa)."' WHERE ID=$id";
	if(@mysql_query($query))
		echo 'Podstrona zostala zaktualizowana';
	else
		echo $error[7];
}

function galeryedit($id)
{
	global $debuge_mode, $error;
	$query="SELECT * FROM galerie WHERE ID=$id";
	$result=mysql_query($query);
	if($r=@mysql_fetch_array($result))
	{
		$this->photoRefresh('galery/'.$r['path'].'/', 0);
		echo '<form action = index.php?module=admin&cmd=galerysave method=post>
<table border=0>
<tr><td><input type=text name=nazwa style="width: 490px;" value="'.stripslashes($r["nazwa"]).'"> numer: '.$r['ID'].'</td></tr>
<tr><td><textarea style="width: 550px; height:500px;" id="elm2" name="tekst" rows="15" cols="80" style="width: 80%">'.stripslashes($r["foredit"]).'</textarea></td></tr>
<tr><td><input type=submit value="Zapisz"></td></tr><input type=hidden name=id value='.$id.'>
</table></form><br><br>dodaj zdjecia do galerii: 
<form enctype="multipart/form-data" action=index.php?module=admin&cmd=photoadd&id='.$id.' method=post><input type=hidden name=id value='.$id.'><table id=pliki border=0><tr><td>
<input onchange=\'addRow("pliki")\' size=70 type=file name=zdjecie[]></td></tr>
</table><input type=submit value="Wyślij"><input type=hidden name=filescount id=filescount value=0></form><br><hr><br>Zdjęcia na serwerze:<br>';
		$this->photoUploaded($r['path']);
		echo '<a href="index.php?module=admin&cmd=creategalery&id='.$id.'">Utwórz galerię automatycznie</a>';
	}
	else
		echo $error[7];
}

function creategalery()
{
	global $id;
	$query="SELECT * FROM galerie WHERE ID=$id";
	$result=mysql_query($query);
	$output = '';
	$edit = '';
	if($r=@mysql_fetch_array($result))
	{
		$path = $r['path'];
		if($handle = opendir('./galery/'.$path.'/'))
		{
			$a = 0;
			$output .= '<table border="0" cellspacing="2" cellpadding="0">';
			$edit .= '<table border="0" cellspacing="2" cellpadding="0">';
		    	while (false !== ($file = readdir($handle))) 
			{
				if(!(($file == '.') || ($file == '..')))
					if(strstr($file, 'miniatura'))
					{
						if($a == 0)
						{
							$output .= '<tr>';
							$edit .= '<tr>';
						}
						$full = str_replace("miniatura-", "", $file);

						$output .= '<td><a rel="lightbox[roadtrip]" href="./galery/'.$path.'/'.$full.'"><img title="" src="./galery/'.$path.'/'.$file.'" alt="" border=0 border=0 /></a></td>';
						$edit .= '<td><img title="./galery/'.$path.'/'.$file.'" src="./galery/'.$path.'/'.$file.'" alt="" border=0 border=0 /></td>';
						if($a < 2)
						{
							$a++;
						}
						else
						{
							$a = 0;
							$output .= '</tr>';
							$edit .= '</tr>';
						}
					}
    			}
    			closedir($handle);
			$output .= '</table>';
			$edit .= '</table>';
			$query="UPDATE galerie SET tresc='".addslashes($output)."', foredit='".addslashes($edit)."' WHERE ID=$id";
			if(@mysql_query($query))
				echo 'Galeria została utworzona';
			else
				echo $error[7];
		}
	}
	echo $output;
	echo '<hr>'.$edit;
}

function galerysave()
{
	global $debuge_mode, $id, $tekst, $nazwa, $error;
	$tekst = stripslashes($tekst);
	$foredit = $tekst;
	$tekst = str_replace("<", " <", $tekst);
	$tekst = str_replace("<p>", "", $tekst);
	$tekst = str_replace("</p>", "", $tekst);
	$proba = explode(" ", $tekst);
	for ($i = 0; $i < count($proba); $i++)
	{
		if($proba[$i] == "<img")
		{
			$file = $proba[$i + 2];
			$file = str_replace("src", "href", $file);
			$file = str_replace("miniatura-", "", $file);
			$proba[$i] = '<a '.$file.' rel="lightbox[roadtrip]">'.$proba[$i];
			$proba[$i + 6] = $proba[$i + 6].'</a>';
		}
	}
	$tekst = implode(" ", $proba);

	$query="UPDATE galerie SET tresc='".addslashes($tekst)."', foredit='".addslashes($foredit)."', nazwa='".addslashes($nazwa)."' WHERE ID=$id";
	if(@mysql_query($query))
		echo 'Galeria została zapisana';
	else
		echo $error[7];
}

function galerydel()
{
	global $debuge_mode, $id, $error;
	$query="SELECT * FROM galerie WHERE ID=$id";
	$result=mysql_query($query);
	$r=@mysql_fetch_array($result);
	$path = './galery/'.$r['path'].'/';
	if($handle = opendir($path))
	{
	    	while (false !== ($file = readdir($handle))) 
		{
			if(!(($file == '.') || ($file == '..')))
				unlink($path.'/'.$file);
    		}
    		closedir($handle); 
	}
	rmdir($path);
	$query="DELETE FROM galerie Where ID=$id";
	if(@mysql_query($query))
	{
		echo 'Galeria została usunięta';
	}
	else
		echo $error[7];
}

function galeryadd()
{
	global $debuge_mode, $error;
	$path = date('YmdGis');
	$query="INSERT INTO galerie (ID, nazwa, tresc, path) VALUES (NULL, 'tytul galerii', 'tresc', '$path')";
	if(@mysql_query($query))
	{
		$id = mysql_insert_id();
		mkdir ('./galery/'.$path.'', 0777);
		$this->galeryedit($id);
	}
	else
		echo $error[7];
}

function photoadd()
{
	global $debuge_mode, $id, $filescount;
	$query="SELECT * FROM galerie WHERE ID=$id";
	$result=mysql_query($query);
	$r=@mysql_fetch_array($result);

	for($i = 0; $i < $filescount; $i++)
	{
		$uploadfile = './galery/'.$r['path'].'/'.plCharset($_FILES['zdjecie']['name'][$i]).'';
		if (move_uploaded_file($_FILES['zdjecie']['tmp_name'][$i], $uploadfile)) 
		{
			$filename = $uploadfile;
			list($width, $height) = getimagesize($uploadfile);
			if(($width > 640) || ($height > 480))
			{
				if($width > $height)
					$raito = 640/$width;
				else
					$raito = 480/$height;
			
				$newwidth = $raito*$width;
				$newheight = $raito*$height;						
		
				$thumb = imagecreatetruecolor($newwidth, $newheight);
				$source = imagecreatefromjpeg($filename);
				imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
				imagejpeg($thumb, './galery/'.$r['path'].'/'.plCharset($_FILES['zdjecie']['name'][$i]).'', 100);
			}

			list($width, $height) = getimagesize($uploadfile);
			if($width > $height)
				$raito = 180/$width;
			else
				$raito = 135/$height;
			$newwidth = $raito*$width;
			$newheight = $raito*$height;
			$thumb = imagecreatetruecolor($newwidth, $newheight);
			$source = imagecreatefromjpeg($filename);
			imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
			imagejpeg($thumb, './galery/'.$r['path'].'/miniatura-'.plCharset($_FILES['zdjecie']['name'][$i]).'', 100);
			echo 'Zdjecie dodane poprawnie: '.$_FILES['zdjecie']['name'][$i].'<br>';
		}
	}
	$this->galeryedit($id);	
}


function photoUploaded($path)
{
	if($handle = opendir('./galery/'.$path.'/'))
	{
		$a = 0;
	    	while (false !== ($file = readdir($handle))) 
		{
			if(!(($file == '.') || ($file == '..')))
				if(strstr($file, 'miniatura'))
				{
					$full = str_replace("miniatura-", "", $file);
					echo '<a href="./galery/'.$path.'/'.$full.'"><img src="./galery/'.$path.'/'.$file.'"></a> ';	
					if($a < 2)
					{
						$a++;
					}
					else
					{
						$a = 0;
						echo '<hr>';
					}
				}
    		}
    		closedir($handle); 
	}
}

function plCharset($string) 
{
	$string = strtr($string, 'ĘęÓóĽšŁłŻżĆćŃń', 'EeOoAaSsLlZzZzCcNn');
	$string = strtr($string, 'ĄŚŹąśź','ASZasz');
	$string = preg_replace("'[[:space:]]'",'',$string);
	$string = strtolower($string);
	return $string;
}

function galeryactive()
{
	global $debuge_mode, $id, $tekst, $nazwa, $error;
	$query="UPDATE galerie SET active=1 WHERE ID=$id";
	if(@mysql_query($query))
		echo 'Galeria została opublikowana';
	else
		echo $error[7];
}

function photoRefresh($directory, $all)
{
	$output = '';
	$delimiter = "\n";
	$output .= 'var tinyMCEImageList = new Array(';
	if (is_dir($directory)) 
	{
		if($all == 1)
			$path = $directory.'/*.jpg';
		else
			$path = $directory.'/miniatura*.jpg';

		foreach (glob($path) as $file)
			$output .= $delimiter. '["'. utf8_encode($file). '", "'. utf8_encode("$file"). '"],';
		$output = substr($output, 0, -1);
		$output .= $delimiter;
	}
	$output .= ');';
	$fp = fopen ("js/lists/images.js", "w");
	fwrite($fp, $output);
}

function upload()
{
	echo '<form enctype="multipart/form-data" action=index.php?module=admin&cmd=uploaded&id='.$id.' method=post>dodaj obrazek na serwer: <input size=50 type=file name=zdjecie> <input type=submit value="Wyślij"></form>';
}

function uploaded()
{
	$uploadfile = strtolower('./upload/'.plCharset($_FILES['zdjecie']['name']).'');
	if (move_uploaded_file($_FILES['zdjecie']['tmp_name'], $uploadfile)) 
	{
		echo '<b>Obrazek został dodany poprawnie </b><hr>';
		$this->uploadstable();
	}
	else
	{
		print "Błąd podczas wysyłania pliku !!\n";
    		print_r($_FILES);
	}
}




function projecttable()
{
	echo '<b><a href=index.php?module=admin&cmd=projectadd>Dodaj nowy projekt</a></b><br><hr>';
	global $error;
	$query="SELECT * FROM projekty";
	$result=mysql_query($query);
	while($r=mysql_fetch_array($result))
	{
		echo '<b>'.stripslashes($r["tytul"]).'</b> ';
		if($_SESSION['admin'] != NULL)
		{
			echo '<a href=index.php?module=admin&cmd=projectedit&id='.$r['ID'].'>[Edycja] </a>| ';
			if ($r['active']!=1)
				echo '<a href=index.php?module=admin&cmd=projectpublic&id='.$r['ID'].'>[Opublikuj]</a> | ';
			echo '<a href=index.php?module=admin&cmd=projectdel&id='.$r['ID'].'>[Usuń]</a>';
		}
		echo '<hr>';
	}
}

function projectadd()
{
	global $debuge_mode, $id, $error;
	$admin = $_SESSION['id'];
	$query="INSERT INTO projekty VALUE(null, 'strona',now(), now(), 'wpisz opis', 'wpisz tytul', 0)";
	if(@mysql_query($query))
	{
		$id = mysql_insert_id();
		$this->projectedit($id);
	}
	else
		echo $error[7];
}

function projectedit($id)
{
	$this->photoRefresh('upload', 1);
	global $debuge_mode, $error;
	$query="SELECT * FROM projekty WHERE ID=$id";
	$result=mysql_query($query);
	if($r=@mysql_fetch_array($result))
		echo '<form action = index.php?module=admin&cmd=projectsave method=post>
<table border=0>
<tr><td>tytul: <input type=text name=tytul style="width: 555px;" value="'.stripslashes($r["tytul"]).'"></td></tr>
<tr><td>www: <input type=text name=www style="width: 555px;" value="'.stripslashes($r["www"]).'"></td></tr>
<tr><td>od: <input type=text name=od style="width: 555px;" value="'.$r["od"].'"></td></tr>
<tr><td>do: <input type=text name=do style="width: 555px;" value="'.$r["do"].'"></td></tr>
<tr><td><textarea id="elm2" name="opis" style="width: 555px; height: 600px" cols="80" style="width: 80%">'.stripslashes($r["opis"]).'</textarea></td></tr>
<input type=hidden name=id value='.$id.'>
</table></form>';
	else
		echo $error[7];
}

function projectsave()
{
	global $debuge_mode, $id, $opis, $tytul, $error, $od, $do, $www;
	$query="UPDATE projekty SET www='".addslashes($www)."', od=date('".$od."'), do=date('".$do."'), opis='".addslashes($opis)."', tytul='".addslashes($tytul)."' WHERE ID=$id";
	if(@mysql_query($query))
	{
		echo '<b>Projekt został zaktualizowany</b><hr>';
		$this->projecttable();
	}
	else
		echo $error[7];
}

function projectdel()
{
	global $debuge_mode, $id, $error;
	$query="DELETE FROM projekty Where id=$id";
	if(@mysql_query($query))
	{
		echo '<b>Projekt został usunięty</b><hr>';
		$this->projecttable();
	}
	else
		echo $error[7];
}

function projectpublic()
{
	global $debuge_mode, $id, $error;
	$query="UPDATE projekty SET active=1 WHERE ID=$id";
	if(@mysql_query($query))
	{
		echo '<b>Projekt zostal opublikowany</b><hr>';
		$this->projecttable();
	}
	else
		echo $error[7];
}
}
?>